package com.vitabuybuy.tv.dialog

import android.content.Context
import android.view.View
import android.view.animation.Animation
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.PopupRefuseInviteBinding
import com.library.common.toast.XToast
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.ScaleConfig

class RefuseInvitePopup
    (
    context: Context,
    private var onConfirm: (content: String) -> Unit
) : BasePopupWindow(context) {

    private lateinit var mBinding: PopupRefuseInviteBinding

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_refuse_invite)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        mBinding = DataBindingUtil.bind<ViewDataBinding>(contentView) as PopupRefuseInviteBinding
        mBinding.btnCancel.setOnClickListener {
            dismiss()
        }
        mBinding.btnAgree.setOnClickListener {
            if(mBinding.etContent.text.isEmpty()){
                XToast.normal(context.getString(R.string.plsease_enter_refuse_reson))
                return@setOnClickListener
            }
            onConfirm.invoke(mBinding.etContent.text.toString())
            dismiss()
        }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withScale(ScaleConfig.CENTER)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withScale(ScaleConfig.CENTER)
            .toDismiss()
    }
}